package monitor;

import java.util.Date;

import jess.JessException;

import monitor.basic.Activity;
import monitor.basic.Monitor;
import monitor.inference.InferenceEngine;
import monitor.transmission.Transmitter;

import socio.Entity;
import socio.hardware.Faucet;
import socio.initiative.Human;

public aspect FaucetMonitor extends Monitor {

	public FaucetMonitor() {
		super();
		try {
			InferenceEngine engine = new InferenceEngine(null, null);
			Transmitter transmitter = new Transmitter();
			this.setTransmitter(transmitter);
			this.setEngine(engine);
			this.start();
		} catch (JessException e) {
			e.printStackTrace();
		}
	}

	after(Faucet faucet, Human who, Date when) returning():
		execution(void Faucet.turnOn(Human,Date))&&target(faucet)&&args(who,when){
		Activity activity = new Activity(who, "turnedOn", faucet, when);
		this.recorder.record(activity);
	}

	after(Faucet faucet, Human who, Date when) returning():
		execution(void Faucet.turnOff(Human,Date))&&target(faucet)&&args(who,when){
		Activity activity = new Activity(who, "turnedOff", faucet, when);
		this.recorder.record(activity);
	}

	before(Faucet faucet, Entity entity, Date when): 
		execution(void Faucet.takeWater(Entity,Date))
		&&target(faucet)
		&&args(entity,when) 
	{
		Activity activity = new Activity(entity, "toTakeWater", faucet, when);
		this.recorder.record(activity);
		this.recorder.record("[" + when + "]" + entity.getId()
				+ " is to take water");
	}

	after(Faucet faucet, Entity entity, Date when) returning() : 
		execution(void Faucet.takeWater(Entity,Date))
		&&target(faucet)
		&&args(entity,when) 
	{
		Activity activity = new Activity(entity, "hasTakenWater", faucet, when);
		this.recorder.record(activity);
		this.recorder.record("[" + when + "]" + entity.getId()
				+ " has taken water");
	}

}
